<?php   
  	/*\
  	 *	Kernel - oh.framework
  	 *	---------------------
  	 *	name: kernel
  	 *  sign: 
  	 *	desc: this module contain kernel level function  	 
  	\*/
	
	/*\
	 *	
	\*/ oh_module_header();
	
	function oh_module_kernel($tokens) {        
        global $oh_object_kernel;
        return $oh_object_kernel;        
	} 
	class oh_class_kernel { 
		function oh_class_kernel() {
		}
		function hibernate($key="dev") {
			global $oh;
			//require_once("CreateZipFile.inc.php");
			//require_once("CreateZipFileMac.inc.php");
			require_once("pclzip.lib.php");
			
			$z = new PclZip($oh['path']."/oh.framework.".$key.".zip");
			$z->add($oh['path']."/modules",	PCLZIP_OPT_REMOVE_PATH,$oh['path']);
			$z->add($oh['path']."/includes",PCLZIP_OPT_REMOVE_PATH,$oh['path']);
		}
		function delete_hibernate($key="dev") {
			global $oh;
			unlink($oh['path']."/oh.framework.".$key.".zip");
		}		
		function distribution($key="dev") {
			global $oh;
			$this->hibernate($key);
			$dist_dir = "oh-php-framework-".$key;
			if (!is_dir(oh("path.script")."/distributions")) {
				if (mkdir(oh("path.script")."/distributions")) {
					oh_message("No!");
				}
			} 			
			if (!is_dir(oh("path.script")."/distributions/".$dist_dir)) {
				mkdir(oh("path.script")."/distributions/".$dist_dir);
			}
			if (!is_dir(oh("path.script")."/distributions/".$dist_dir."/oh.framework")) {
				mkdir(oh("path.script")."/distributions/".$dist_dir."/oh.framework");
			}
			copy($oh['path']."/modules/kernel/demo.php",oh("path.script")."/distributions/".$dist_dir."/demo.php");

			copy($oh['path']."/index.php",oh("path.script")."/distributions/".$dist_dir."/oh.framework/index.php");			
			copy($oh['path']."/.htaccess",oh("path.script")."/distributions/".$dist_dir."/oh.framework/.htaccess");			
			copy($oh['path']."/oh.framework.php",oh("path.script")."/distributions/".$dist_dir."/oh.framework/oh.framework.php");
			copy($oh['path']."/oh.framework.mini.php",oh("path.script")."/distributions/".$dist_dir."/oh.framework/oh.framework.mini.php");
			copy($oh['path']."/oh.framework.".$key.".zip",oh("path.script")."/distributions/".$dist_dir."/oh.framework/oh.framework.".$key.".zip");
			
			require_once("pclzip.lib.php");
			$z = new PclZip(oh('path.script')."/distributions/".$dist_dir.".zip");
			$z->add(oh('path.script')."/distributions/".$dist_dir."/oh.framework",PCLZIP_OPT_REMOVE_PATH,oh('path.script')."/distributions");
			$z->add(oh('path.script')."/distributions/".$dist_dir."/demo.php",PCLZIP_OPT_REMOVE_PATH,oh('path.script')."/distributions");					
			$this->delete_hibernate($key);			
		}
		function distribution_url($key="dev") {
			$dist_dir = "oh-php-framework-".$key;
			return dirname(oh("url.script"))."/distributions/".$dist_dir.".zip";
		}
		function list_modules() {
			global $oh;
			$modules = array();
			$temp_modules = scandir($oh['path']."/modules");			
			foreach($temp_modules as $module) {
				if (oh_is_name($module)) {
					$modules[] = $module;
				}
			}
			return $modules;
		}
		function register_modules() {
			$ms = $this->list_modules();
			foreach($ms as $m) {
				define($m,$m);
			}
		}
		function module_get_info($modulename) {
			$info = array();
			if (file_exists(oh_module_interface_file($modulename))) {
				$temp = file_get_contents(oh_module_interface_file($modulename),FILE_BINARY,NULL,1,400);
				$info["name"] = oh("string")->substr($temp,"name:","\n");
				$info["sign"] = oh("string")->substr($temp,"sign:","\n");
				$info["description"] = oh("string")->substr($temp,"description:","\n");
				$info["error"] = false;
				return $info;	
			} else {
				$info["name"] = $modulename;
				$info["sign"] = "unsigned";
				$info["error"] = "module not contain interface file";
				return $info;
			}			
		}
		function info() {
			echo oh_wellcome();	
		}
	}
	global $oh_object_kernel;
	$oh_object_kernel = new oh_class_kernel();
?>
